﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Collections;

using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Text.RegularExpressions;
using System.Web;

using System.Xml.Xsl;
using System.Xml.Schema;

using System.Diagnostics;
using System.Reflection;


namespace SchematronTestFramework
{
    class GetAssertMetas
    {
        private string fileName;
        private XmlDocument doc;
        private XmlNodeList patternList;
        private XmlNodeList ruleList;
        private List<XmlNodeList> assertList;


        public string getFileName()
        {
            return fileName;
        }
        public GetAssertMetas(string file)
        {
            fileName = file;
            doc = new XmlDocument();
            doc.Load(fileName);

            patternList = doc.GetElementsByTagName("pattern");
            ruleList = doc.GetElementsByTagName("rule");

            XmlNodeList asserts = doc.GetElementsByTagName("assert");
            assertList = new List<XmlNodeList>();
            assertList.Add(asserts);
            XmlNodeList reports = doc.GetElementsByTagName("report");
            assertList.Add(reports);
        }

        public List<AssertMeta> split()
        {
            List<AssertMeta> metas = new List<AssertMeta>();
            foreach (XmlNode pattern in patternList)
            {
                XmlNodeList pat_rule = pattern.ChildNodes;
                foreach (XmlNode rule in pat_rule)
                {
                    if (rule.Name.CompareTo("rule") == 0)
                    {
                        XmlNodeList rule_ass = rule.ChildNodes;
                        foreach (XmlNode assert in rule_ass)
                        {
                            if (assert.Name.CompareTo("assert") == 0 || assert.Name.CompareTo("report") == 0)
                            {
                                metas.Add(new AssertMeta(pattern, rule, assert));
                            }
                        }
                    }
                }
            }
            return metas;
        }


    }
}
